﻿using System;
using log4net;
using log4net.Config;

namespace sharpxbot.Utils.Logging
{
    public static class Logger
    {
        public static void Write(string message, LogMessageType messageType)
        {
            if (!isConfigured)
            {

                XmlConfigurator.Configure();
                isConfigured = true;
            }

            switch (messageType)
            {
                case LogMessageType.Error:
                    log.Error(message);
                    break;
                case LogMessageType.Debug:
                    log.Debug(message);
                    break;
                case LogMessageType.Fatal:
                    log.Fatal(message);
                    break;
                case LogMessageType.Info:
                    log.Info(message);
                    break;
            }
        }

        public static void Write(string message, Exception ex, LogMessageType messageType)
        {
            if (!isConfigured)
            {

                XmlConfigurator.Configure();
                isConfigured = true;
            }

            switch (messageType)
            {
                case LogMessageType.Error:
                    log.Error(message, ex);
                    break;
                case LogMessageType.Debug:
                    log.Debug(message, ex);
                    break;
                case LogMessageType.Fatal:
                    log.Fatal(message, ex);
                    break;
                case LogMessageType.Info:
                    log.Info(message, ex);
                    break;
            }
        }

        private static ILog log = LogManager.GetLogger(typeof(Logger));
        private static bool isConfigured = false;
    }
}
